package com.jianjun.project.monitor.operlog;

import com.jfinal.aop.Before;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.jianjun.project.common.model.SysOperLog;

import java.util.List;

/**
 * 操作日志 服务层处理
 *
 * @author source
 */
public class SysOperLogService {
    private final SysOperLog dao = new SysOperLog().dao();

    public Page<SysOperLog> paginate(SysOperLog model) {
        SqlPara sqlParaDb = Db.getSqlPara("querySysOperLog", Kv.by("cond", model.toMap()).set(model.getColumnAsc()));
        return dao.paginate(model.getPageNum(), model.getPageSize(), sqlParaDb);
    }

    /**
     * 查询系统操作日志集合
     */
    public List<SysOperLog> selectOperLogList(Model<SysOperLog> model) {
        SqlPara sqlParaDb = Db.getSqlPara("querySysOperLog", Kv.by("cond", model.toMap()));
        return dao.find(sqlParaDb);
    }

    /**
     * 批量删除系统操作日志
     */
    @Before(Tx.class)
    public boolean deleteOperLogByIds(Long[] ids) {
        for (Long id : ids) {
            dao.deleteById(id);
        }
        return true;
    }

    /**
     * 清空操作日志
     */
    public void cleanOperLog() {
        Db.template("deleteOperLog").update();
    }
}
